import Vue from 'vue'
import Vuex from 'vuex'
import allGoodsApi from "@/http/allGoodsApi";
import loginApi from "@/http/loginApi";
import shoppingcardApi from "@/http/shoppingcardApi";

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    shoppingdata: {},
    userInfo:{},
    selectgoods:{},
    total:{},
    count:{},
    ids:{},
  },
  mutations: {
    SET_TYPE(state,type){
      sessionStorage.setItem('type',type);
      state.type = type;
    },
    SET_SHOPPINGDATA(state,val){
      state.shoppingdata = val;
    },
    SET_USERINFO(state,val){
      state.userInfo = val;
    },
    SET_SELECTGOODS(state,val){
      state.selectgoods = val;
    },
    SET_TOTAL(state,val){
      state.total = val;
    },
    SET_COUNT(state,val){
      state.count = val;
    },
    SET_IDS(state,val){
      state.ids = val;
    }
  },
  actions: {
    GET_SHOPPINGDATA_ACTIONS(context, id){
      allGoodsApi.getone(id).then(res =>{
        console.log("res:", res.data.data);
        context.commit("SET_SHOPPINGDATA",res.data.data)
      })
    },
    GET_USERINFO_ACTIONS(context){
      loginApi.getInfo().then(res =>{
        console.log("res:", res.data.data.loginUser);
        context.commit("SET_USERINFO",res.data.data.loginUser)
      })
    },
    GET_SELECTGOODS_ACTIONS(context, ids){
      shoppingcardApi.getmany(ids).then(res =>{
        console.log("res123:", res.data.data);
        context.commit("SET_SELECTGOODS",res.data.data)
      })
    },

  },
  modules: {}
})
